﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RN.ERP.DAL.Context;
using RN.ERP.Entity.ResultModels;

namespace RN.ERP.DAL.ZbdlryDAL
{
    public class AuthorityDAL
    {
        private ZBDL_Context dbContext = new ZBDL_Context();

        public IList<UserRoleModel> GetUserList(string name, string userName)
        {
            string sql = @"select u.id,u.UserGuid,u.name,u.username,u.bgrade,r.areacode from t_sys_users u
 left join t_sys_userRole re
 on u.userguid=re.UserGuid and re.isdel=0
 left join t_sys_roles r
 on re.roleguid=r.RoleGuid and r.isdel=0 
 where 1 = 1 ";

            if(!string.IsNullOrEmpty(name))
            {
                sql += " and u.name like '%" + name + "%' ";
            }

            if(!string.IsNullOrEmpty(userName))
            {
                sql += " and u.username like '%" + userName+ "%' ";
            }

            string areacode = System.Configuration.ConfigurationManager.AppSettings["Area"];
            if ("06" == areacode)
            {
                sql += " and u.areacode like '06%' ";
            }

            var list = dbContext.Database.SqlQuery<UserRoleModel>(sql).Take(20).ToList();
            return list;
        }

    }
}
